﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class DocumentEntity : ISerializable
    {
        private DocumentType typeField;

        private string serieField;

        private string numberField;

        private string issuedField;

        private System.Nullable<System.DateTime> issueDateField;

        private Employee employeeField;

        private static readonly DocumentEntity theOneObject = new DocumentEntity();

        public static DocumentEntity GetDocumentEntity()
        {
            return theOneObject;
        }
        /// <remarks/>
        public DocumentType Type
        {
            get
            {
                return this.typeField;
            }
            set
            {
                this.typeField = value;
            }
        }

        /// <remarks/>
        public string Serie
        {
            get
            {
                return this.serieField;
            }
            set
            {
                this.serieField = value;
            }
        }

        /// <remarks/>
        public string Number
        {
            get
            {
                return this.numberField;
            }
            set
            {
                this.numberField = value;
            }
        }

        /// <remarks/>
        public string Issued
        {
            get
            {
                return this.issuedField;
            }
            set
            {
                this.issuedField = value;
            }
        }
        public Employee Employee
        {
            get
            {
                return employeeField;
            }
            set
            {
                employeeField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)]
        public System.Nullable<System.DateTime> IssueDate
        {
            get
            {
                return this.issueDateField;
            }
            set
            {
                this.issueDateField = value;
            }
        }
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("Type", typeField);
            info.AddValue("Serie", serieField);
            info.AddValue("Number", numberField);
            info.AddValue("Issued", issuedField);
            info.AddValue("IssueDate", issueDateField);
        }
        public DocumentEntity()
        {
        }

        public List<Classes.DocumentEntity> getDocumentEntityList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                emp.Document.Employee = emp;
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.Select(em => em.Document).ToList();

            return cr;
        }
    }
}
